using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Security.Cryptography;

namespace Tes
{
    class Class1
    {
        SqlCommand sqlCommand;
        SqlConnection sqlConnection;
        string connectionString;
        public Class1()
        {
            connectionString = "server=(local);" +
               "database=RecruitVietnam;" +
               "Integrated Security=SSPI;";
            sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = connectionString;
            sqlConnection.Open();
        }
        
        public int ExecuteNonQuery()
        {
            string commandText = "Update tblRCAccounts set Password = '" + RCVEncryptingPassword("11111111") + "'";
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = commandText;
            sqlCommand.Connection = sqlConnection;            
            
            int rows = sqlCommand.ExecuteNonQuery();           
            sqlCommand.Dispose();
            return rows;
        }  
        ~Class1()
        {
            if (sqlConnection.State != ConnectionState.Open)
            {
                sqlConnection.Close();
            }
            sqlConnection.Dispose();
        }
        public string RCVEncryptingPassword(string password)
        {
            string encryptPassword = password + "RCV";
            byte[] passwordBytes = Encoding.UTF8.GetBytes(encryptPassword);

            HashAlgorithm hash = new MD5CryptoServiceProvider();
            byte[] hashBytes = hash.ComputeHash(passwordBytes);

            encryptPassword = Convert.ToBase64String(passwordBytes);
            return encryptPassword;
        }
    }
}
